package com.cddx.logistics.controller;

import com.cddx.logistics.domain.dto.WarehousesettingsQueryDTO;
import com.cddx.logistics.domain.pojo.Warehousesettings;
import com.cddx.logistics.domain.vo.WarehouseVO;
import com.cddx.logistics.domain.vo.WarehousesettingsVO;
import com.cddx.logistics.service.WarehousesettingsService;
import com.cddx.logistics.util.model.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/warehouse")
@Api(tags = "仓库管理")
public class WarehousesettingsController {
    @Resource
    private WarehousesettingsService warehouseService;

    @GetMapping("/queryPage")
    @ApiOperation("分页查询仓库")
    public R queryPage(WarehousesettingsQueryDTO queryDTO) {
        PageInfo<WarehousesettingsVO> pageInfo = warehouseService.queryPage(queryDTO);
        return R.ok(pageInfo);
    }

    @PostMapping("/add")
    @ApiOperation("添加仓库")
    public R add(Warehousesettings warehouse) {
        return warehouseService.add(warehouse) ? R.ok("添加成功") : R.error("添加失败");
    }

    @PostMapping("/update")
    @ApiOperation("修改仓库信息")
    public R update(Warehousesettings warehouse) {
        return warehouseService.update(warehouse) ? R.ok("修改成功") : R.error("修改失败");
    }

    @GetMapping("/delete")
    @ApiOperation("删除仓库")
    public R delete(Long warehouseId) {
        return warehouseService.delete(warehouseId) ? R.ok("删除成功") : R.error("删除失败");
    }

    @PostMapping("/batchDelete")
    @ApiOperation("批量删除仓库")
    public R batchDelete(@RequestBody List<Long> warehouseIds) {
        return warehouseService.batchDelete(warehouseIds) ? R.ok("批量删除成功") : R.error("批量删除失败");
    }
}